﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class GreetingMessageInChannelsController : ControllerBase
    {

        private readonly IGreetingMessageInChannelAppService _app;
        public GreetingMessageInChannelsController(IGreetingMessageInChannelAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("greetingMessageInChannels/{id:Guid}")]
        public ActionResult<GreetingMessageInChannelDto> Get([FromRoute] Guid id,[FromQuery] string include="")
        {
            GreetingMessageInChannelDto greetingMessageInChannel = _app.Get(id,include);
            return Ok(greetingMessageInChannel);
        }

        [HttpGet]
        [Route("bots/{botId:Guid}/greetingMessageInChannels")]
        public ActionResult<IEnumerable<GreetingMessageInChannelDto>> GetList([FromRoute] Guid botId, [FromQuery] string include = "")
        {
            IEnumerable<GreetingMessageInChannelDto> list = _app.GetList(botId,include);
            return Ok(list);
        }

        [HttpPut]
        [Route("greetingMessageInChannels/{id:Guid}")]
        public ActionResult<GreetingMessageInChannelDto> Put([FromRoute] Guid id, [FromBody] GreetingMessageInChannelUpdateDto dto)
        {
            GreetingMessageInChannelDto GreetingMessageInChannel = _app.Update(id, dto);
            return Ok(GreetingMessageInChannel);
        }

        [HttpPost]
        [Route("bots/{botId:Guid}/greetingMessageInChannels")]
        public ActionResult<GreetingMessageInChannelDto> Post([FromRoute] Guid botId, [FromBody] GreetingMessageInChannelCreateDto dto)
        {
            GreetingMessageInChannelDto GreetingMessageInChannel = _app.Add(botId,dto);
            return CreatedAtAction(nameof(Get), new { id = GreetingMessageInChannel.Id }, GreetingMessageInChannel);
        }

        [HttpDelete]
        [Route("greetingMessageInChannels/{id:Guid}")]
        public ActionResult<GreetingMessageInChannelDto> Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
